<?php
require_once '../../classes/includeAll_Layer2.php';

//$sessionId = 5; //debug
//$isAdmin=true;
$supplierID = filter_input(INPUT_POST,"supplierID");
$oldSupplierID = filter_input(INPUT_POST,"oldSupplierID");

$valuesContact = array();
$columnContact = array();

$nameSupplier = filter_input(INPUT_POST, "nameSupplier", FILTER_SANITIZE_SPECIAL_CHARS);
if ($nameSupplier != null || $nameSupplier != false) 
{
    array_push($valuesContact, $nameSupplier);
    array_push($columnContact, "name");
}

$contactSaleOffice = filter_input(INPUT_POST, "contactSaleOffice", FILTER_SANITIZE_SPECIAL_CHARS);
if ($contactSaleOffice != null || $contactSaleOffice != false) 
{
    array_push($valuesContact, $contactSaleOffice);
    array_push($columnContact, "contactSalesOffice");
}

$contactService = filter_input(INPUT_POST, "contactService", FILTER_SANITIZE_SPECIAL_CHARS);
if ($contactService != null || $contactService != false) 
{
    array_push($valuesContact, $contactService);
    array_push($columnContact, "contactService");
}

$noteSupplier = filter_input(INPUT_POST, "noteSupplier", FILTER_SANITIZE_SPECIAL_CHARS);
if ($noteSupplier != null || $noteSupplier != false) 
{
    array_push($valuesContact, $noteSupplier);
    array_push($columnContact, "note");
}

if($supplierID == null || $supplierID == false || $oldSupplierID == null || $oldSupplierID == false|| !$isAdmin)
{
  echo "false";
  exit();
}
else
{
    require '../../resources/getConnection.php';
    
    $supplierClass = new Suppliers($connection);
    
    $supplier = $supplierClass->getSupplierBy($supplierID, null);
    if(count($valuesContact) > 0)
    {
        $supplierClass->UpdateSupplier($oldSupplierID, $columnContact, $valuesContact);
    }
    echo json_encode(array("name" => $supplier['name'], "contactSalesOffice" => $supplier['contactSalesOffice'], "contactService" => $supplier['contactService'], "note" => $supplier['note']));

}

